/**
 * @ProjectName: 
 * @Copyright: 2014 lisheng  All Right Reserved.
 * @address: toughheart@163.com
 * @date: 2015年1月2日 下午8:23:14
 * @Description: 本内容未经本人允许禁止使用、转发.
 */

package org.apache.lucene.demo;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.facet.Facets;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SearcherManager;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;

/**
 * 
 * @author lisheng
 * @date 2015年1月2日 下午8:23:14
 * @version V1.0
 */
public interface LuceneServer extends Closeable {

	String INDEX_DIR = "index";
	
	/**
	 * 索引文件目录
	 * 
	 * @author lisheng
	 * @date 2015年1月2日 下午8:40:06
	 * @version V1.0
	 * @return
	 */
	public Directory getDir();

	public Directory openDir(String path);

	public IndexWriter getIndexWriter();

	public IndexReader getIndexReader();

	public SearcherManager getSearcherManager();
	
	public void closeIndexWriter();

	public void closeIndexReader();

	public LuceneServer reOpenIndexReader();

	public void rollback();

	public void commit();

	public boolean isAutoCommit();

	public Analyzer getDefaultAnalyzer();

	/**
	 * 
	 * @author lisheng
	 * @date 2015年1月2日 下午8:44:39
	 * @version V1.0
	 * @return
	 */
	boolean isOpened();

	/**
	 * 
	 * @author lisheng
	 * @date 2015年1月2日 下午8:44:45
	 * @version V1.0
	 * @return
	 */
	String getAddress();

	public LuceneServer openIndexWriter(Analyzer analyzer, OpenMode openMode);

	public boolean open();

	public boolean open(String address);

	public boolean open(String address, Analyzer analyzer, OpenMode openMode);

	public boolean reopen();

	public boolean reopen(String address);

	public boolean reopen(String address, Analyzer analyzer, OpenMode openMode);

	public void addDoc(Document doc);

	public void addDoc(IndexWriter indexWriter, Document doc);

	public void addDoc(IndexWriter indexWriter, List<IndexableField> list);

	public void addDoc(List<IndexableField> list);

	public void addDocs(IndexWriter indexWriter, List<Document> docs);

	public void addDocs(List<Document> docs);

	public void deleteAllDoc();

	public void deleteAllDoc(IndexWriter indexWriter);

	public void deleteDoc(IndexWriter indexWriter, Query... query);

	public void deleteDoc(IndexWriter indexWriter, Term... term);

	public void deleteDoc(Query... query);

	public void deleteDoc(Term... term);

	public TopDocs search(IndexSearcher searcher, Query query, int pageSize);

	public TopDocs search(IndexSearcher searcher, Query query, int page,
			int pageSize);

	public void updateDoc(IndexWriter indexWriter, Term term, Document doc);

	public void updateDoc(Term term, Document doc);

	public Facets searchFacet(Query query) throws IOException;
	/**
	 * 
	 * @author lisheng
	 * @date 2015年1月3日 下午1:28:41
	 * @version V1.0
	 * @return
	 */
	boolean isNearRealTime();

	
	/**
	 * 
	 * @author lisheng
	 * @date 2015年1月3日 下午1:36:56
	 * @version V1.0
	 * @param indexSearcher
	 */
	void release(IndexSearcher indexSearcher);

	public IndexSearcher acquire();

	public void refushTimestamp();
}
